home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / MacPerl 5.1.3 / Mac_Perl_513_src / perl5.002 / x2p / a2p.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-20  |  8.2 KB  |  434 lines  |  [TEXT/KAHL]

  1. /* $RCSfile: a2p.h,v $$Revision: 4.1 $$Date: 92/08/07 18:29:09 $
  2.  *
  3.  *    Copyright (c) 1991, Larry Wall
  4.  *
  5.  *    You may distribute under the terms of either the GNU General Public
  6.  *    License or the Artistic License, as specified in the README file.
  7.  *
  8.  * $Log:    a2p.h,v $
  9.  */
  10.  
  11. #ifdef macintosh
  12. #include "::embed.h"
  13. #include "::config.h"
  14. #undef HAS_BCOPY
  15. #undef HAS_BZERO
  16. #else
  17. #include "../embed.h"
  18. #define VOIDUSED 1
  19. #include "../config.h"
  20. #endif
  21.  
  22. #if defined(__STDC__) || defined(vax11c) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus)
  23. # define STANDARD_C 1
  24. #endif
  25.  
  26. /* Use all the "standard" definitions? */
  27. #if defined(STANDARD_C) && defined(I_STDLIB)
  28. #   include <stdlib.h>
  29. #endif /* STANDARD_C */
  30.  
  31. #include <stdio.h>
  32.  
  33. #ifdef I_MATH
  34. #include <math.h>
  35. #endif
  36.  
  37. #ifdef I_SYS_TYPES
  38. #  include <sys/types.h>
  39. #endif
  40.  
  41.  
  42. #ifdef USE_NEXT_CTYPE 
  43. #include <appkit/NXCType.h>
  44. #else
  45. #include <ctype.h>
  46. #endif
  47.  
  48. #define MEM_SIZE Size_t
  49.  
  50. #if defined(I_STRING) || defined(__cplusplus)
  51. #   include <string.h>
  52. #else
  53. #   include <strings.h>
  54. #endif
  55.  
  56. #ifndef HAS_BCOPY
  57. #   define bcopy(s1,s2,l) memcpy(s2,s1,l)
  58. #endif
  59. #ifndef HAS_BZERO
  60. #   define bzero(s,l) memset(s,0,l)
  61. #endif
  62.  
  63. #if !defined(HAS_STRCHR) && defined(HAS_INDEX) && !defined(strchr)
  64. #define strchr index
  65. #define strrchr rindex
  66. #endif
  67.  
  68.  
  69. #ifdef I_TIME
  70. #   include <time.h>
  71. #endif
  72.  
  73. #ifdef I_SYS_TIME
  74. #   ifdef I_SYS_TIME_KERNEL
  75. #    define KERNEL
  76. #   endif
  77. #   include <sys/time.h>
  78. #   ifdef I_SYS_TIME_KERNEL
  79. #    undef KERNEL
  80. #   endif
  81. #endif
  82.  
  83. #ifndef MSDOS
  84. #  if defined(HAS_TIMES) && defined(I_SYS_TIMES)
  85. #    include <sys/times.h>
  86. #  endif
  87. #endif
  88.  
  89. #ifdef DOSISH
  90. # if defined(OS2)
  91. #   include "../os2ish.h"
  92. # else
  93. #   include "../dosish.h"
  94. # endif
  95. #else
  96. # if defined(VMS)
  97. #   include "../vmsish.h"
  98. # endif
  99. #endif
  100.  
  101. #ifndef STANDARD_C
  102. /* All of these are in stdlib.h or time.h for ANSI C */
  103. Time_t time();
  104. struct tm *gmtime(), *localtime();
  105. char *strchr(), *strrchr();
  106. char *strcpy(), *strcat();
  107. #endif /* ! STANDARD_C */
  108.  
  109. #include "handy.h"
  110. #define Nullop 0
  111.  
  112. #define OPROG        1
  113. #define OJUNK        2
  114. #define OHUNKS        3
  115. #define ORANGE        4
  116. #define OPAT        5
  117. #define OHUNK        6
  118. #define OPPAREN        7
  119. #define OPANDAND    8
  120. #define OPOROR        9
  121. #define OPNOT        10
  122. #define OCPAREN        11
  123. #define OCANDAND    12
  124. #define OCOROR        13
  125. #define OCNOT        14
  126. #define ORELOP        15
  127. #define ORPAREN        16
  128. #define OMATCHOP    17
  129. #define OMPAREN        18
  130. #define OCONCAT        19
  131. #define OASSIGN        20
  132. #define OADD        21
  133. #define OSUBTRACT    22
  134. #define OMULT        23
  135. #define ODIV        24
  136. #define OMOD        25
  137. #define OPOSTINCR    26
  138. #define OPOSTDECR    27
  139. #define OPREINCR    28
  140. #define OPREDECR    29
  141. #define OUMINUS        30
  142. #define OUPLUS        31
  143. #define OPAREN        32
  144. #define OGETLINE    33
  145. #define OSPRINTF    34
  146. #define OSUBSTR        35
  147. #define OSTRING        36
  148. #define OSPLIT        37
  149. #define OSNEWLINE    38
  150. #define OINDEX        39
  151. #define ONUM        40
  152. #define OSTR        41
  153. #define OVAR        42
  154. #define OFLD        43
  155. #define ONEWLINE    44
  156. #define OCOMMENT    45
  157. #define OCOMMA        46
  158. #define OSEMICOLON    47
  159. #define OSCOMMENT    48
  160. #define OSTATES        49
  161. #define OSTATE        50
  162. #define OPRINT        51
  163. #define OPRINTF        52
  164. #define OBREAK        53
  165. #define ONEXT        54
  166. #define OEXIT        55
  167. #define OCONTINUE    56
  168. #define OREDIR        57
  169. #define OIF        58
  170. #define OWHILE        59
  171. #define OFOR        60
  172. #define OFORIN        61
  173. #define OVFLD        62
  174. #define OBLOCK        63
  175. #define OREGEX        64
  176. #define OLENGTH        65
  177. #define OLOG        66
  178. #define OEXP        67
  179. #define OSQRT        68
  180. #define OINT        69
  181. #define ODO        70
  182. #define OPOW        71
  183. #define OSUB        72
  184. #define OGSUB        73
  185. #define OMATCH        74
  186. #define OUSERFUN    75
  187. #define OUSERDEF    76
  188. #define OCLOSE        77
  189. #define OATAN2        78
  190. #define OSIN        79
  191. #define OCOS        80
  192. #define ORAND        81
  193. #define OSRAND        82
  194. #define ODELETE        83
  195. #define OSYSTEM        84
  196. #define OCOND        85
  197. #define ORETURN        86
  198. #define ODEFINED    87
  199. #define OSTAR        88
  200.  
  201. #ifdef DOINIT
  202. char *opname[] = {
  203.     "0",
  204.     "PROG",
  205.     "JUNK",
  206.     "HUNKS",
  207.     "RANGE",
  208.     "PAT",
  209.     "HUNK",
  210.     "PPAREN",
  211.     "PANDAND",
  212.     "POROR",
  213.     "PNOT",
  214.     "CPAREN",
  215.     "CANDAND",
  216.     "COROR",
  217.     "CNOT",
  218.     "RELOP",
  219.     "RPAREN",
  220.     "MATCHOP",
  221.     "MPAREN",
  222.     "CONCAT",
  223.     "ASSIGN",
  224.     "ADD",
  225.     "SUBTRACT",
  226.     "MULT",
  227.     "DIV",
  228.     "MOD",
  229.     "POSTINCR",
  230.     "POSTDECR",
  231.     "PREINCR",
  232.     "PREDECR",
  233.     "UMINUS",
  234.     "UPLUS",
  235.     "PAREN",
  236.     "GETLINE",
  237.     "SPRINTF",
  238.     "SUBSTR",
  239.     "STRING",
  240.     "SPLIT",
  241.     "SNEWLINE",
  242.     "INDEX",
  243.     "NUM",
  244.     "STR",
  245.     "VAR",
  246.     "FLD",
  247.     "NEWLINE",
  248.     "COMMENT",
  249.     "COMMA",
  250.     "SEMICOLON",
  251.     "SCOMMENT",
  252.     "STATES",
  253.     "STATE",
  254.     "PRINT",
  255.     "PRINTF",
  256.     "BREAK",
  257.     "NEXT",
  258.     "EXIT",
  259.     "CONTINUE",
  260.     "REDIR",
  261.     "IF",
  262.     "WHILE",
  263.     "FOR",
  264.     "FORIN",
  265.     "VFLD",
  266.     "BLOCK",
  267.     "REGEX",
  268.     "LENGTH",
  269.     "LOG",
  270.     "EXP",
  271.     "SQRT",
  272.     "INT",
  273.     "DO",
  274.     "POW",
  275.     "SUB",
  276.     "GSUB",
  277.     "MATCH",
  278.     "USERFUN",
  279.     "USERDEF",
  280.     "CLOSE",
  281.     "ATAN2",
  282.     "SIN",
  283.     "COS",
  284.     "RAND",
  285.     "SRAND",
  286.     "DELETE",
  287.     "SYSTEM",
  288.     "COND",
  289.     "RETURN",
  290.     "DEFINED",
  291.     "STAR",
  292.     "89"
  293. };
  294. #else
  295. extern char *opname[];
  296. #endif
  297.  
  298. EXT int mop INIT(1);
  299.  
  300. union u_ops {
  301.     int ival;
  302.     char *cval;
  303. };
  304. #if defined(iAPX286) || defined(M_I286) || defined(I80286)     /* 80286 hack */
  305. #define OPSMAX (64000/sizeof(union u_ops))    /* approx. max segment size */
  306. #else
  307. #define OPSMAX 50000
  308. #endif                             /* 80286 hack */
  309. EXT union u_ops ops[OPSMAX];
  310.  
  311. typedef struct string STR;
  312. typedef struct htbl HASH;
  313.  
  314. #include "str.h"
  315. #include "hash.h"
  316.  
  317.  
  318. /* A string is TRUE if not "" or "0". */
  319. #define True(val) (tmps = (val), (*tmps && !(*tmps == '0' && !tmps[1])))
  320. EXT char *Yes INIT("1");
  321. EXT char *No INIT("");
  322.  
  323. #define str_true(str) (Str = (str), (Str->str_pok ? True(Str->str_ptr) : (Str->str_nok ? (Str->str_nval != 0.0) : 0 )))
  324.  
  325. #define str_peek(str) (Str = (str), (Str->str_pok ? Str->str_ptr : (Str->str_nok ? (sprintf(buf,"num(%g)",Str->str_nval),buf) : "" )))
  326. #define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
  327. #define str_gnum(str) (Str = (str), (Str->str_nok ? Str->str_nval : str_2num(Str)))
  328. EXT STR *Str;
  329.  
  330. #define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
  331.  
  332. /* Prototypes for things in a2p.c */
  333. int aryrefarg _(( int arg ));
  334. int bl _(( int arg, int maybe ));
  335. void dump _(( int branch ));
  336. int fixfargs _(( int name, int arg, int prevargs ));
  337. int fixrargs _(( char *name, int arg, int prevargs ));
  338. void fixup _(( STR *str ));
  339. int numary _(( int arg ));
  340. int oper0 _(( int type ));
  341. int oper1 _(( int type, int arg1 ));
  342. int oper2 _(( int type, int arg1, int arg2 ));
  343. int oper3 _(( int type, int arg1, int arg2, int arg3 ));
  344. int oper4 _(( int type, int arg1, int arg2, int arg3, int arg4 ));
  345. int oper5 _(( int type, int arg1, int arg2, int arg3, int arg4, int arg5 ));
  346. void putlines _(( STR *str ));
  347. void putone _(( void ));
  348. int rememberargs _(( int arg ));
  349. char * scannum _(( char *s ));
  350. char * scanpat _(( char *s ));
  351. int string _(( char *ptr, int len ));
  352. void yyerror _(( char *s ));
  353. int yylex _(( void ));
  354.  
  355. EXT int line INIT(0);
  356.  
  357. EXT FILE *rsfp;
  358. EXT char buf[2048];
  359. EXT char *bufptr INIT(buf);
  360.  
  361. EXT STR *linestr INIT(Nullstr);
  362.  
  363. EXT char tokenbuf[2048];
  364. EXT int expectterm INIT(TRUE);
  365.  
  366. #ifdef DEBUGGING
  367. EXT int debug INIT(0);
  368. EXT int dlevel INIT(0);
  369. #define YYDEBUG 1
  370. extern int yydebug;
  371. #endif
  372.  
  373. EXT STR *freestrroot INIT(Nullstr);
  374.  
  375. EXT STR str_no;
  376. EXT STR str_yes;
  377.  
  378. EXT bool do_split INIT(FALSE);
  379. EXT bool split_to_array INIT(FALSE);
  380. EXT bool set_array_base INIT(FALSE);
  381. EXT bool saw_RS INIT(FALSE);
  382. EXT bool saw_OFS INIT(FALSE);
  383. EXT bool saw_ORS INIT(FALSE);
  384. EXT bool saw_line_op INIT(FALSE);
  385. EXT bool in_begin INIT(TRUE);
  386. EXT bool do_opens INIT(FALSE);
  387. EXT bool do_fancy_opens INIT(FALSE);
  388. EXT bool lval_field INIT(FALSE);
  389. EXT bool do_chop INIT(FALSE);
  390. EXT bool need_entire INIT(FALSE);
  391. EXT bool absmaxfld INIT(FALSE);
  392. EXT bool saw_altinput INIT(FALSE);
  393.  
  394. EXT bool nomemok INIT(FALSE);
  395.  
  396. EXT char const_FS INIT(0);
  397. EXT char *namelist INIT(Nullch);
  398. EXT char fswitch INIT(0);
  399.  
  400. EXT int saw_FS INIT(0);
  401. EXT int maxfld INIT(0);
  402. EXT int arymax INIT(0);
  403. EXT char *nameary[100];
  404.  
  405. EXT STR *opens;
  406.  
  407. EXT HASH *symtab;
  408. EXT HASH *curarghash;
  409.  
  410. #define P_MIN        0
  411. #define P_LISTOP    5
  412. #define P_COMMA        10
  413. #define P_ASSIGN    15
  414. #define P_COND        20
  415. #define P_DOTDOT    25
  416. #define P_OROR        30
  417. #define P_ANDAND    35
  418. #define P_OR        40
  419. #define P_AND        45
  420. #define P_EQ        50
  421. #define P_REL        55
  422. #define P_UNI        60
  423. #define P_FILETEST    65
  424. #define P_SHIFT        70
  425. #define P_ADD        75
  426. #define P_MUL        80
  427. #define P_MATCH        85
  428. #define P_UNARY        90
  429. #define P_POW        95
  430. #define P_AUTO        100
  431. #define P_MAX        999
  432.  
  433. EXT int an;
  434.